<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>MetaMaskTest</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script language="javascript">

        function setText(text){
             document.getElementById("text").innerHTML = text;
        }

        var password = "tianya123456qwe";
        var walletFileName;
        var credentials;

        // js 调用 Android
        // 连接以太坊客户端
        function connectETHClientAction(){
            var web3ClientVersion = window.web3jExBridge.connectClient();
            setText(web3ClientVersion); //  ccm/v1.1/fc-rpc-2.0.0-dev
        }

        // 根据密码 创建一个钱包文件
        // 返回文件名
        function createFullWalletAction(){
            walletFileName = window.web3jExBridge.createFullWallet(password);
            setText(walletFileName);
        }
        function createLightWalletAction(){
            walletFileName = window.web3jExBridge.createLightWallet(password);
            setText(walletFileName);
        }
        function createBip39WalletAction(){
            window.web3jExBridge.createBip39Wallet(password);
            //setText(result);
        }
         function createBip39WalletCallback(bip39Wallet){
             setText(bip39Wallet);
        }




        //根据密码，钱包文件 加载钱包文件
        //返回地址，公钥，私钥 json
        function loadWalletAction(){
            credentials = window.web3jExBridge.loadWallet(password,walletFileName);
            setText(credentials);
            //var obj = JSON.parse(credentials); //由JSON字符串转换为JSON对象
            //setText(obj.address);//address
            //setText(obj.ecKeyPair.privateKey);//privateKey
            //setText(obj.ecKeyPair.publicKey);//publicKey
        }

        // 根据私钥加载钱包
        // 返回新的地址，公钥，私钥 json
        function loadWalletByPrivateKeyAction(){
            var privateKey = "3b8020d16ba2021ec7ff880a3323c40893dfd2146c4dfbb139ed8d5174b4bcc3";
            //var credentialsTemp = window.web3jExBridge.loadWallet(password,walletFileName);
            //var obj = JSON.parse(credentials); //由JSON字符串转换为JSON对象
            //var privateKey = obj.ecKeyPair.privateKey+""

            var credentials = window.web3jExBridge.loadWalletByPrivateKey(privateKey);
            setText(credentials);
            //真正私钥地址 ??
           // var obj = JSON.parse(credentials); //由JSON字符串转换为JSON对象
           // var prikey = "0x" + (obj.ecKeyPair.privateKey).toString(16);
           // setText(prikey)
        }




        //查询指定地址的余额
        function getBlanceOfAction(){
            var address = "0x46Bf521e93e3fE4e3413CC586187b9b85FFAFd3a";
            var blanceETH = window.web3jExBridge.getBlanceOf(address);
            setText(blanceETH);
        }

        function getNonceAction(){
             var address = "0x46Bf521e93e3fE4e3413CC586187b9b85FFAFd3a";
             var nonce = window.web3jExBridge.getNonce(address);
             setText(nonce);
        }

        //转账以太网 等待5s 以上
        function transferAction(){
            var address = "0x49e57bF84a70DB940Fe6d4d9Ca0F53e3B79a0264";
            var amount = 0.1;
            var transactionReceipt = window.web3jExBridge.transfer(address,amount);
            setText(transactionReceipt);
        }
        //转账 自定义
        function transferCustomAction(){
            var  gasPrice = "100";
            var  gasLimit = "21000";
            var address = "0x49e57bF84a70DB940Fe6d4d9Ca0F53e3B79a0264";
            var amount = "1";
            var ethSendTransaction = window.web3jExBridge.transferCustom(gasPrice,gasLimit,address,amount);
            setText(ethSendTransaction);
        }
       // function transferCustomCallback(ethSendTransaction){
      //      setText(ethSendTransaction);
      //  }


        //??
        //获取交易列表
        function getTransactionListAction(){

             var blockNumber = "890457";
             var blockEthBlock = window.web3jExBridge.getTransactionList(blockNumber);
             setText(blockEthBlock);
        }

         //获取交易详情
        function getTransactionByHashAction(){
             var hash = "0x7a6181a4ad8c7eff9bb27723893c949c49ed56c16a29ae024088c8df0d7f635f";
             //var hash = "0x7553f7020ebd53ea726fa5232b975d45c47faac6d582c7c712d8036e5647d86d";
            var tranReceipt =  window.web3jExBridge.getTransactionByHash(hash);
            setText(tranReceipt);
        }
        //function getTransactionByHashCallback(ethTransaction){
        //   setText(ethTransaction);
        //}


         function web3jObserverAction(){
               window.web3jExBridge.web3jObserver();
         }

        function getAccountsAction(){
               window.web3jExBridge.getAccountList();
         }
        function depositAction(){
               window.web3jExBridge.deposit();
         }
         function withdrawAction(){
               window.web3jExBridge.withdraw();
         }

    </script>
</head>
<body>
<!--//点击按钮则调用callAndroid函数-->
<button type="button" value="按钮1" name="按钮1" id="button1" onclick="connectETHClientAction()">按钮1
    connectETHClientAction
</button>
</br></br>
<button type="button" value="按钮11" name="按钮11" id="button11" onclick="getAccountsAction()">按钮11
    getAccountsAction
</button>
</br></br>
</br></br>


<button type="button" value="按钮2" name="按钮2" id="button2" onclick="createFullWalletAction()">按钮2
    createFullWalletAction
</button>
</br></br>

<button type="button" value="按钮22" name="按钮22" id="button22" onclick="createLightWalletAction()">按钮22
    createLightWalletAction
</button>
</br></br>

<button type="button" value="按钮23" name="按钮23" id="button23" onclick="createBip39WalletAction()">按钮23
    createBip39WalletAction
</button>
</br></br>
</br></br>


<button type="button" value="按钮3" name="按钮3" id="button3" onclick="loadWalletAction()">按钮3
    loadWalletAction
</button>
</br></br>


<button type="button" value="按钮4" name="按钮4" id="button4" onclick="loadWalletByPrivateKeyAction()">按钮4
    loadWalletByPrivateKeyAction
</button>
</br></br>
</br></br>


<button type="button" value="按钮5" name="按钮5" id="button5" onclick="getBlanceOfAction()">按钮5
    getBlanceOfAction
</button>
</br></br>
<button type="button" value="按钮5x" name="按钮5x" id="button5x" onclick="getNonceAction()">按钮5x
    getNonceAction
</button>
</br></br>
</br></br>

<button type="button" value="按钮6" name="按钮6" id="button6" onclick="transferAction()">按钮6
    transferAction
</button>
</br></br>

<button type="button" value="按钮7" name="按钮7" id="button7" onclick="transferCustomAction()">按钮6
    transferCustomAction
</button>
</br></br>
</br></br>

<button type="button" value="按钮8" name="按钮8" id="button8" onclick="getTransactionListAction()">按钮8
    getTransactionListAction
</button>
</br></br>

<button type="button" value="按钮9" name="按钮9" id="button9" onclick="getTransactionByHashAction()">按钮9
    getTransactionByHashAction
</button>
</br></br>
</br></br>

<button type="button" value="按钮10" name="按钮10" id="button10" onclick="web3jObserverAction()">按钮10
    web3jObserverAction
</button>
</br></br></br></br>

<button type="button" value="按钮10x" name="按钮10x" id="button10x" onclick="depositAction()">按钮10
    depositAction
</button>
</br></br>

<button type="button" value="按钮10xq" name="按钮10xq" id="button10xq" onclick="withdrawAction()">按钮10
    withdrawAction
</button>
</br></br>


<span id="text">text</span></br>
</br></br>

</body>
</html>